import request from '@/utils/request'

export function getTableList(query) {
  return request({
    url: 'api/generator/tables',
    method: 'get',
    params: query
  })
}


/**
 *
 * @param tableName
 * @param type 根据类型 判断所需要的数据
 *  0 生成代码
 *  1 预览代码
 *  2 打包下载
 * @returns {AxiosPromise}
 */
export function generator(tableName, type) {
  return request({
    url: 'api/generator/' + tableName + '/' + type,
    method: 'post',
    responseType: type === 2 ? 'blob' : ''
  })
}


export function save(data) {
  return request({
    url: 'api/generator',
    data,
    method: 'put'
  })
}

export function sync(tables) {
  return request({
    url: 'api/generator/sync',
    method: 'post',
    data: tables
  })
}

